﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xunit;
using Moq;

namespace MvcWiki.Test.Repository.FileSystem.WikiNamespaceFileSystemRepository
{
    public class SaveWikiNamespaceFacts
    {
        [Fact]
        public void Saves_WikiNamespace()
        {
            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            var wikiMarkupProvider = new Mock<MvcWiki.Markup.IWikiMarkupProvider>();
            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();
            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();

            var wikiNamespaceRepository = new MvcWiki.Repository.FileSystem.WikiNamespaceFileSystemRepository(repositoryFactory.Object, wikiMarkupProvider.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            var wikiNamespace = new MvcWiki.Model.WikiNamespace
            {
                Name = "Namespace",
                Markup = new MvcWiki.Model.WikiMarkup()
            };

            wikiNamespaceRepository.SaveWikiNamespace(wikiNamespace);
        }

        [Fact]
        public void Calls_IUnitOfWork_Saved()
        {
            var wikiNamespace = new MvcWiki.Model.WikiNamespace
            {
                Name = "Namespace",
                Markup = new MvcWiki.Model.WikiMarkup()
            };

            var repositoryFactory = new Mock<MvcWiki.Repository.IWikiRepositoryFactory>();
            var wikiMarkupProvider = new Mock<MvcWiki.Markup.IWikiMarkupProvider>();
            var unitOfWork = new Mock<MvcWiki.Repository.IUnitOfWork>();
            var fileSystem = new Mock<MvcWiki.Repository.FileSystem.IFileSystemWrapper>();

            var wikiNamespaceRepository = new MvcWiki.Repository.FileSystem.WikiNamespaceFileSystemRepository(repositoryFactory.Object, wikiMarkupProvider.Object, unitOfWork.Object, "c:\\path", fileSystem.Object);

            unitOfWork.Setup(x => x.Saved(wikiNamespace, wikiNamespaceRepository));

            wikiNamespaceRepository.SaveWikiNamespace(wikiNamespace);

            unitOfWork.VerifyAll();
        }
    }
}
